package cn.iocoder.yudao.module.trade.config.mq;

import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.api.shop.info.message.ShopAuditPassMessage;
import cn.iocoder.yudao.module.trade.config.service.TradeConfigService;
import cn.iocoder.yudao.module.trade.config.vo.TradeConfigSaveReqVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 交易配置 事件消费者
 *
 * @author 山野羡民
 */
@Component
@Slf4j
public class TradeConfigConsumer {

    @EventListener
    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    public void onMessage(ShopAuditPassMessage message) {
        log.info("[trade][onMessage][店铺审核通过事件({})]", message);
        TradeConfigSaveReqVO tradeConfigSaveReqVO = new TradeConfigSaveReqVO();
        tradeConfigSaveReqVO.setAfterSaleRefundReasons(List.of("质量不好", "与描述不符"));
        tradeConfigSaveReqVO.setAfterSaleReturnReasons(List.of("不想要了", "拍错"));
        tradeConfigSaveReqVO.setDeliveryExpressFreeEnabled(true);
        tradeConfigSaveReqVO.setDeliveryExpressFreePrice(0);
        tradeConfigSaveReqVO.setDeliveryPickUpEnabled(false);
        SpringUtil.getBean(TradeConfigService.class).saveTradeConfig(message.getShopInfo().getId(), tradeConfigSaveReqVO);
    }

}
